/**
 * 组织管理
 */
Package("com.green.web.tree");
var validateMessage = $("span[key='validateMessage']");
com.green.web.tree={
		init:function(number){
			var onclickBefor;//单击节点函数
			var setting = {
				view: {
					selectedMulti: false
				},
				async: {
					enable: true,
					url:ctx+"/funPermission/tree?number="+number,
					autoParam:["id"],
					dataFilter: com.green.web.tree.filter
				},
				callback: {
					beforeClick: com.green.web.tree.beforeClick,
					beforeAsync: com.green.web.tree.beforeAsync
				}
			};
			//加载树
			var treeObj = $.fn.zTree.init($("#treeDemo"), setting);
			$("#refreshNode").bind("click", {type:"refresh", silent:false}, com.green.web.tree.refreshNode);
			$("#refreshNodeSilent").bind("click", {type:"refresh", silent:true}, com.green.web.tree.refreshNode);
		},
		filter:function(treeId, parentNode, childNodes) {
			if (!childNodes) return null;
			for (var i=0, l=childNodes.length; i<l; i++) {
				childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
			}
			return childNodes;
		},
		beforeClick:function(treeId, treeNode) {
			$("#parentId").val(encodeURIComponent(treeNode.id));
			$("#parentName").val(treeNode.name);
			com.green.web.FunPermissionManager.queryData(treeNode.id);
		    if(com.green.web.tree.onclickBefor){
		       return com.green.web.tree.onclickBefor(treeId,treeNode);
		    }
		},
		beforeAsync:function(treeId, treeNode) {
			return treeNode ? treeNode.level < 10 : true;
		},
		refreshNode:function(e) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			type = e.data.type,
			silent = e.data.silent,
			nodes = zTree.getSelectedNodes();
			if (nodes.length == 0) {
				alert("请先选择一个父节点");
			}
			for (var i=0, l=nodes.length; i<l; i++) {
				zTree.reAsyncChildNodes(nodes[i], type, silent);
				if (!silent) zTree.selectNode(nodes[i]);
			}
		},
		getBizTypeValue:function(){
			var bizTypeValue = "";
			$("input[name='bizType']").each(function(i,temp){
				if(temp.checked){
					bizTypeValue += temp.value+",";
				}
			});
			return bizTypeValue;
		}
		
};
